<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="CommonUtil/CommonUtil.js"></script>
    <script type="text/javascript" charset="utf-8">
        //享元模式：内在数据（static）（出厂商，型号，出厂日期）
        //外在数据（拥有者，车牌号，最近登记日期）
        var Car = function (make,model,year) {
            this.make = make;
            this.model = model;
            this.year = year;
        }
        Car.prototype = {
            constructor:Car,
            getMake:function () {
                return this.make;
            },
            getModel:function () {
                return this.model;
            },
            getYear:function () {
                return this.year;
            }
        }
        //闭包工厂
        var CarFactory = (function () {
            //用于盛装已经生产好的car
            var createdCars = {};
            return {
                createdCar:function (make,model,year) {
                    //如果createCar对象中已经存在当前的make,model,year
                    if(createdCars[make+model+year]){
                        return createdCars[make+model+year];
                    }else{
                        var car = new Car(make,model,year);
                        createdCars[make+model+year] = car;
                    }
                }
            }
        })()
        //单体模式（外在数据和内在数据结合在一起）
        var CarRecordManager = (function () {
            var carRecordDataBase ={};
            return {
                addCarRecord:function (make,model,year,owner,tag,renewDate) {
                    var car = CarFactory.createCar(make,model,year);
                    carRecordDataBase[tag]={
                        owner:owner,
                        renewDate:renewDate,
                        car:car
                    };
                },
                renewRegistration:function (tag,newRenwDate) {
                    carRecordDataBase[tag].renewDate = newRenwDate;
                }
            }
        })();
        var arr = [];
        var startTime = new Date().getTime();
        for(var i = 0;i<5000000;i++){
            arr.push(CarFactory.createdCar('上海大众','迈腾','2012-02-03','huangchao','F8888','2013-04-11'))
        }
        var endTime = new Date().getTime();
        alert(endTime-startTime);
    </script>
</head>
<body>
</body>
</html>